package com.situ.mall.order.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.situ.mall.common.util.Result;
import com.situ.mall.order.entity.vo.CartVO;
import com.situ.mall.order.service.ICartService;
import com.situ.mall.pojo.entity.order.Cart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 购物车 前端控制器
 * </p>
 *
 * @author Z
 * @since 2024-10-14
 */
@RestController
@RequestMapping("/order/cart")
public class CartController {
    @Autowired
    private ICartService cartService;
    @RequestMapping("/add")
    public Result add(@RequestBody Cart cart) {
        //System.out.println(cart);
        CartVO cartVO = cartService.add(cart);
        return Result.ok(cartVO);
    }
    @GetMapping("/selectByUserId/{id}")
    public Result<List<CartVO>> selectByUserId(@PathVariable Long id) {
        List<CartVO> list = cartService.selectByUserId(id);
        System.out.println(id);
        return Result.ok(list);
    }
    @RequestMapping("/update")
    public Result update(@RequestBody Cart cart) {
        UpdateWrapper<Cart> wrapper = new UpdateWrapper<>();
        //wrapper.eq("user_id", cart.getUserId());
        //wrapper.eq("product_id", cart.getProductId());
        cartService.updateById(cart);
        return Result.ok();
    }
    @RequestMapping("/updateCheckedAll")
    public Result updateCheckedAll(@RequestBody Cart cart) {
        cartService.updateCheckedAll(cart);
        return Result.ok();
    }
}

